package com.gsj.system.controller;


import com.gsj.common.pojo.R;
import com.gsj.system.config.OperLog;
import com.gsj.system.eneity.Role;
import com.gsj.system.pojo.RoleVo;
import com.gsj.system.pojo.RolevoSecond;
import com.gsj.system.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: clmseighth
 * @description:
 * @author: 张巍蓝
 * @create: 2021-07-24 09:27
 **/

@RestController
@RequestMapping("/system/menu")
public class RoleController {
    @Autowired
    private RoleService roleService;
    @PutMapping("editUserRole/{UserId}")
    public R editUserRole(@PathVariable("UserId") Integer UserId,
                          @RequestBody List<Integer> role
    ){
        return roleService.editUserRole(UserId,role);
    }

    @GetMapping("queryBYuserfRole")
    @OperLog( title= "通过userid查询角色表",operatorType ="0",business_type = "0")
    public R queryBYuserfRole(Integer userId){
        return roleService.queryBYuserfRole(userId);
    }

    @PostMapping("queryAllRole/{currentPage}/{pageSize}")
    @OperLog( title= "查询所有角色",operatorType ="0",business_type = "0")
    public R queryAllRole(@PathVariable("currentPage") Integer currentPage,
                          @PathVariable("pageSize") Integer pageSize,
                          @RequestBody RoleVo roleVo
    ){
        return roleService.queryAllRole(currentPage,pageSize,roleVo);
    }
    @PutMapping("editRoleStatus")
    @OperLog( title= "通过roleid更改角色状态",operatorType ="0",business_type = "0")
    public R editRoleStatus(Integer id,Integer status){
        return roleService.editRoleStatus(id,status);
    }
    @GetMapping("queryRoleByRoleId")
    @OperLog( title= "通过roleid查询角色表",operatorType ="0",business_type = "0")
    public R queryRoleByRoleId(Integer id){
        return roleService.queryRoleByRoleId(id);
    }
    @PutMapping("editRoleByRoleId/{username}")
    @OperLog( title= "通过roleid更改角色表",operatorType ="0",business_type = "0")
    public R editRoleByRoleId( @PathVariable("username") String username,
                               @RequestBody Role role
                              ){
        return roleService.editRoleByRoleId(role,username);
    }
    @PostMapping("addNewRole/{username}")
    @OperLog( title= "新增角色表",operatorType ="0",business_type = "0")
    public R addNewRole( @PathVariable("username") String username,
                         @RequestBody RolevoSecond role
    ){
        return roleService.addNewRole(role,username);
    }
    @DeleteMapping("deleterolebyRoleId")
    @OperLog( title= "通过roleid删除角色表",operatorType ="0",business_type = "0")
    public R deleteRoleByRoleId(Integer roleId){
        return roleService.deleteRoleByRoleId(roleId);
    }
    @GetMapping("confirmFenRole")
    @OperLog( title= "通过roleid修改角色表",operatorType ="0",business_type = "0")
    public R confirmFenROle (@RequestParam(value="userRoleIds",required=false) List<Integer
            > userRoleIds,@RequestParam  Integer userId){
        return roleService.confirmFenMenu(userId,userRoleIds);
    }





}
